// components/custom-navbar/index.js
Component({
    properties: {
        title: {
            type: String,
            value: ''
        },
        leftTitle: {
            type: String,
            value: ''
        },
        backgroundColor: {
            type: String,
            value: 'transparent'
        },
        textColor: {
            type: String,
            value: '#ffffff'
        },
        showBack: {
            type: Boolean,
            value: false
        },
        isCoverNav: {
            type: Boolean,
            value: false
        },
        isHomePage: {
            type: Boolean,
            value: false
        },
        showTitle: {
            type: Boolean,
            value: false
        },
        showRight: {
            type: Boolean,
            value: false
        }
    },

    data: {
        statusBarHeight: 0,
        navBarHeight: 44
    },

    lifetimes: {
        attached() {
            // 获取系统信息
            const systemInfo = wx.getSystemInfoSync();
            this.setData({
                statusBarHeight: systemInfo.statusBarHeight,
                navBarHeight: systemInfo.platform === 'ios' ? 44 : 44
            });
            wx.setStorageSync('navHeight', this.data.statusBarHeight + this.data.navBarHeight)
        }
    },

    methods: {
        onBack() {
            // 触发返回事件
            this.triggerEvent('back');

            // 默认返回行为
            const pages = getCurrentPages();
            if (pages.length > 1) {
                wx.navigateBack();
            } else {
                wx.switchTab({
                    url: '/pages/index/index'
                });
            }
        }
    }
});